feat: support :global{} & :local{} for css module#1
Conversation
Summary of ChangesHello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the CSS Modules feature by implementing support for the non-functional Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for non-functional :global and :local pseudo-classes for CSS modules, which is a great feature enhancement. The implementation is straightforward, handling these cases in parse_non_ts_pseudo_class and removing the previous error-handling logic. I have one suggestion to reduce some code duplication, but otherwise, the changes look good.
src/selector.rs
Outdated
| "local" if self.options.css_modules.is_some() => Local { selector: Box::new(Selector::from(Component::Nesting)) }, | ||
| "global" if self.options.css_modules.is_some() => Global { selector: Box::new(Selector::from(Component::Nesting)) }, |
There was a problem hiding this comment.
These two match arms are very similar. You can combine them into a single arm to reduce code duplication and improve maintainability.
"local" | "global" if self.options.css_modules.is_some() => {
let selector = Box::new(Selector::from(Component::Nesting));
if name.eq_ignore_ascii_case("local") {
Local { selector }
} else {
Global { selector }
}
},- Add serialize_selector_with_css_modules and serialize_component_with_css_modules functions
- Pass handle_css_modules parameter to control CSS modules processing
- In :global context, skip CSS modules hashing for class names and IDs
- Fixes issue where :global { .class } was incorrectly hashed
- Remove the !combinators_exhausted condition that was causing assertion failure - This was incorrectly copied from the original implementation
- Remove serialize_selector_old and serialize_component_old functions - These were causing combinators_exhausted assertion failures - Keep only the working implementations
- Remove combinators_exhausted variable and its assertion - This was causing assertion failures in selector serialization - The logic was incorrect and not needed for the CSS modules fix
- Add :global( and ) wrapper around the selector content - This ensures the output matches CSS Modules specification - The inner selector should not be hashed when inside :global()
…selector chains - Pass mutable handle_css_modules through selector/component serializers - When encountering :global, disable hashing for the rest of the chain - Keep :local to serialize inner selector with hashing on - Output :global(...) wrapper explicitly
- Detect implicit non-functional :global alias (:global(&)) - Do not emit wrapper, just disable hashing for the rest of the chain - Preserve explicit :global(<selector>) in output
No description provided.